import {forEach} from "lodash";

class ArrayQueue{
    #queue:any;
    constructor() {
        this.#queue = [];
    }

    put(item:any){
        this.#queue.push(item);
    }

    putAll(array:[]){
        for(const item of array){
            this.#queue.push(item);
        }
    }

    take(){
        if(this.#queue.length <= 0){
            return null;
        }
        return this.#queue.shift();
    }

    clear(){
        this.#queue = [];
    }

    size(){
        return this.#queue.length;
    }
    remove(uuid:string){
        for(let i = this.#queue.length - 1; i >= 0 ; i --){
            const item = this.#queue[i];
            if(item.uuid == uuid){
                this.#queue.splice(i,1);
            }
        }
    }

    preAdd(item:any){
        this.#queue.splice(0,0,item);
    }
}

export  default ArrayQueue;